package com.ltxtiyu.video.api;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ltxtiyu.video.common.DataGridParam;
import com.ltxtiyu.video.service.app.MusicService;
import com.ltxtiyu.video.tool.ParamTool;
import com.ltxtiyu.video.tool.Tool;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 关于音乐
 */
@RestController
public class ApiMusic {
    @Reference
    MusicService musicService;

    /**
     * 查看音乐详情
     * @param request
     * @return
     */
    @RequestMapping("/music/detail")
    public String musicDetail(HttpServletRequest request){
        Map<String, String> params = ParamTool.requestToParamMap(request);
        return musicService.musicDetail(params);
    }

    /**
     * 音乐列表
     * @param request
     * @return
     */
    @RequestMapping("/music/list")
    public String musicList(HttpServletRequest request){
        Map<String, String> params = ParamTool.requestToParamMap(request);
        DataGridParam dgp = Tool.genDataGridParam(request);
        Integer start = (dgp.getPage() - 1) * dgp.getRows();
        Integer rows = dgp.getRows();
        params.put("start", String.valueOf(start));
        params.put("rows", String.valueOf(rows));
        return musicService.musicList(params);
    }
}
